package cool.doudou.doudada.mqtt.auto.configuration;

import cool.doudou.doudada.mqtt.config.MqttConfig;
import cool.doudou.doudada.mqtt.config.MqttMessageConfig;
import cool.doudou.doudada.mqtt.core.handler.MqttGatewayHandler;
import cool.doudou.doudada.mqtt.core.helper.MqttHelper;
import cool.doudou.doudada.mqtt.properties.MqttProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * MqttAutoConfiguration
 *
 * @author jiangcs
 * @since 2022/3/3
 */
@EnableConfigurationProperties({MqttProperties.class})
@Import({MqttConfig.class, MqttMessageConfig.class})
@AutoConfiguration
public class MqttAutoConfiguration {
    @ConditionalOnMissingBean(MqttHelper.class)
    @Bean
    public MqttHelper mqttHelper(@Autowired(required = false) MqttGatewayHandler mqttGatewayHandler) {
        return new MqttHelper(mqttGatewayHandler);
    }
}
